package com.itheima.tliasmanager.config;

import com.itheima.tliasmanager.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * springmvc配置类：
 *     配置拦截器、异常处理、视图解析器、消息转换器
 */
@Configuration
public class WebConfig  implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    //注册拦截器到springmvc框架中
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //使用方法提供的拦截器注册器进行注册
        registry.addInterceptor(loginInterceptor)
                //配置拦截器：拦截的路径
                .addPathPatterns("/**")  //拦截所有请求
                .excludePathPatterns("/login"); // 放行登录请求
    }
}
